package ltd.hyangyang.rpc.core.serialize;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class RpcDecoder  extends ByteToMessageDecoder {
    Class<?> clazz;
    public RpcDecoder(Class<?> clazz){
        this.clazz=clazz;
    }
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        byte[] bytes = new byte[byteBuf.capacity()];
        byteBuf.readBytes(bytes);
        Object object = KryoSerialize.deserialize(bytes,clazz);
        list.add(object);
    }
}
